Skip to content

Fix variable shadowing in Claude Code nesting traces Python example - #5817

Draft
langsmith-fleet[bot] wants to merge 2 commits into
mainfrom
docs/claude-code-tracing-avoid-variable-shadowing
Draft

Fix variable shadowing in Claude Code nesting traces Python example#5817
langsmith-fleet[bot] wants to merge 2 commits into
mainfrom
docs/claude-code-tracing-avoid-variable-shadowing

Conversation

@langsmith-fleet

Copy link
Copy Markdown
Contributor

Summary

  • Add missing import os to the Python "Nesting traces under an existing run" example
  • Replace the inline {**os.environ, ...} dict spread with a named claude_env dict that explicitly excludes LANGSMITH_* SDK variables from the subprocess environment
  • Removes potential variable shadowing between the outer LANGSMITH_* SDK env vars (set via os.environ) and the CC_LANGSMITH_* plugin vars the subprocess uses
  • The "Option 2: Shell environment variables" fallback section is unchanged and remains intact

Links

Verification

Not run; docs-only copy and code example change.

Reviewers

Requested review from: Kathryn May (@katmayb), Florence Morris (@fjmorris)

Add missing 'import os', and replace the inline **os.environ dict
spread with a named claude_env dict that explicitly excludes LANGSMITH_*
SDK variables from the subprocess environment. This avoids potential
variable shadowing between the outer SDK env vars and the CC_LANGSMITH_*
plugin vars used by the subprocess.
@github-actions github-actions Bot added langsmith For docs changes to LangSmith external User is not a member of langchain-ai labels Sep 2, 2026
Replace the single env-var approach with two options:
- Option 1 (recommended): write plugin config to a temp JSON file and
  pass it via 'claude --settings <path>'. This fully isolates CC plugin
  vars from the parent process environment, eliminating variable
  shadowing between LANGSMITH_* SDK vars and CC_LANGSMITH_* plugin vars.
- Option 2 (fallback): pass env vars directly to subprocess, explicitly
  excluding LANGSMITH_* keys to avoid shadowing.

Both Python and TypeScript examples are included for each option.
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Mintlify preview branch generated: preview-docscl-1788308092-594beb1

Site preview: https://langchain-5e9cc07a-preview-docscl-1788308092-594beb1.mintlify.site

Important

Preview links may take a few minutes to start working while the deployment finishes.

Changed documentation pages (preview deep links):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external User is not a member of langchain-ai langsmith For docs changes to LangSmith

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants